package com.yunhe.device.client;

import com.yunhe.common.model.authority.RealStation;
import com.yunhe.device.client.fallback.AuthorityFallbackFactory;
import com.yunhe.common.model.ResultObject;
import com.yunhe.common.model.authority.Firm;
import com.yunhe.common.model.authority.Station;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import springfox.documentation.annotations.ApiIgnore;

import java.util.List;
import java.util.Optional;

/**
 * @author liuronglei
 */
@ApiIgnore
@FeignClient(value = "yh-authority", fallbackFactory = AuthorityFallbackFactory.class)
public interface AuthorityClient {

    @RequestMapping(value = "/stations/{id}", method = RequestMethod.GET)
    ResultObject<Station> getStationById(@PathVariable("id") Long id);

    /**
     * 根据单位ID获得电站列表
     * @param firmId 单位ID
     */
    @RequestMapping(value = "/stations/byFirm/{firmId}", method = RequestMethod.GET)
    ResponseEntity<ResultObject<List<Station>>> getStationByFirmId(
            @PathVariable("firmId") Long firmId);

    @RequestMapping(value = "/stations/{id}/resources", method = RequestMethod.POST)
    ResponseEntity<ResultObject> stationBindResource(
            @PathVariable("id") Long id,
            @RequestParam("type") String type,
            @RequestParam("resourceId") List<Long> resourceIdList);

    /**
     * 根据单位代码获得单位
     * @param code 单位代码
     */
    @RequestMapping(value = "/firms/byCode/{code}", method = RequestMethod.GET)
    ResponseEntity<ResultObject<Firm>> getFirmByCode(
            @PathVariable("code") Long code);

    @RequestMapping(value = "/firms/{id}/resources", method = RequestMethod.POST)
    ResponseEntity<ResultObject> firmBindResource(
            @PathVariable("id") Long id,
            @RequestParam("type") String type,
            @RequestParam("resourceId") Long resourceId);

    @RequestMapping(value = "/realStation/searchByStationId/{stationId}",method = RequestMethod.GET)
    ResponseEntity<ResultObject<Iterable<RealStation>>> findRealStationByStationId(@PathVariable("stationId") Long stationId);

    @RequestMapping(value = "/realStation/searchStationAndOfficeByStationId/{stationId}",method = RequestMethod.GET)
    ResponseEntity<ResultObject<Iterable<RealStation>>> searchStationAndOfficeByStationId(@PathVariable("stationId") Long stationId);

    @RequestMapping(value = "/realStation/searchById/{id}",method = RequestMethod.GET)
    ResponseEntity<ResultObject<RealStation>> findByRealStationId(@PathVariable("id") Long id);
}
